<?php
class SellerApp extends BaseApp {
	function index() {
		$TB_seller = & $this->_model('seller');
		$data = $TB_seller->show();

	 	$citydata = & $GLOBALS['SCup']->_get_city_data();
		
		$citylist = array();
		foreach($citydata as $value)
		{
		    $citylist[$value['id']] = $value['name'];
		}		
		
        $this->assign('citylist', $citylist);

		$this->assign('lw_data', $data['data']);
		$this->assign('lw_page', $data['page']);
		$this->assign('view_charset', VIEW_CHARSET);
		$this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
		$this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
		$this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));
		$this->assign('site_url', SITE_URL);
		$this->assign('web_view_dir', SITE_URL . '/admin/view/default/');

		$this->display('seller_list.view.html');
	}

	function add() {
	 	$citydata = & $GLOBALS['SCup']->_get_city_data();
		   
        $this->assign('citydata', $citydata);

		$this->assign('view_charset', VIEW_CHARSET);
		$this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
		$this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
		$this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));
		$this->assign('site_url', SITE_URL);
		$this->assign('web_view_dir', SITE_URL . '/admin/view/default/');

		$this->display('seller_add.view.html');
	}

	function addpost() {
		$data = $_POST['data'];
		$data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		$data['picture']='';
		if($_FILES['postfile1']['tmp_name'])
	    { 		
	    include(ROOT_PATH.'/lib/upfile.lib.php');	  
		$upfile = new Upfile('seller'); 	  
	    $updata = $upfile->_batch_upfile('seller');
		if(!empty($updata)&&isset($updata[1]['path']))
		{ 
		   $data['picture']=$updata[1]['path'];
		}		
		}		
		
		$TB_seller = & $this->_model('seller');
		$TB_seller->post($data);
		$this->index();
	}

	function edit() {
		$id = intval($_GET['id']);

		$TB_seller = & $this->_model('seller');
		$data = $TB_seller->oneshow($id);
	 	$citydata = & $GLOBALS['SCup']->_get_city_data();
	   
        $this->assign('citydata', $citydata);
		
		$this->assign('data', $data);
		$this->assign('view_charset', VIEW_CHARSET);
		$this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
		$this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
		$this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));
		$this->assign('site_url', SITE_URL);
		$this->assign('web_view_dir', SITE_URL . '/admin/view/default/');
		
		$this->display('seller_edit.view.html');
	}

	function editpost() {
		$id = intval($_POST['id']);
		$data = $_POST['data'];
		$TB_seller = & $this->_model('seller');	
		$data['picture']='';
		if($_FILES['postfile1']['tmp_name'])
	    { 			
	    include(ROOT_PATH.'/lib/upfile.lib.php');	  
		$upfile = new Upfile('seller'); 	  
	    $updata = $upfile->_batch_upfile('seller');

		if(!empty($updata)&&isset($updata[1]['path']))
		{ 
		   $tempdata = $TB_seller->oneshow($id);
		  
		   if($tempdata['picture'])
		   {
              $pic_dir = ROOT_PATH . '/' . UPFILE_PATH . '/' . $tempdata['picture'];	
		     if(!is_dir($pic_dir)&&file_exists($pic_dir))
		     {
		       del_file($pic_dir);	
		     }			  
			  
		   }
		   $data['picture']=$updata[1]['path'];
		}		
		}

		$TB_seller->editaction($id, $data);
		$this->index();
	}

	function del() {
		$id = intval($_GET['id']);
		$TB_seller = & $this->_model('seller');
		   $tempdata = $TB_seller->oneshow($id);
		  
		   if($tempdata['picture'])
		   {
              $pic_dir = ROOT_PATH . '/' . UPFILE_PATH . '/' . $tempdata['picture'];	
		     if(!is_dir($pic_dir)&&file_exists($pic_dir))
		     {
		       del_file($pic_dir);	
		     }	
		   }		
		
		$TB_seller->del($id);
		$this->index();
	}
}
?>
